<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>workers</title>
</head>
<body>
<button id="button">按钮</button>
<script src="./worker-1.1.js"></script>
<script>
  const worker = create((self, id) => {
    let time = 0;
    if (!self.timerMap) self.timerMap = new Map();

    const postTimer = () => {
      time++
      let hour = Math.floor(time / 60);
      let minute = time % 60;

      if (hour < 10) hour = `0${hour}`;
      if (minute < 10) minute = `0${minute}`;

      self.timerMap.set(id, `${hour}:${minute}`)

      self.postMessage(self.timerMap)
    }

    if (self.timer) clearInterval(self.timer);
    self.timer = setInterval(postTimer, 1000);

    postTimer()
  });

  if (!worker) {
    throw new Error('Need correctly parameter!');
  }

  worker.onmessage = e => {
    if (e.data?.has('222')) {
      e.data?.delete('111')
    }

    console.log(e.data)
  };

  worker.postMessage('111');

  setTimeout(() => {
    worker.postMessage('222');
  }, 1000 * 4)


</script>
</body>
</html>
